package com.r_z.controller;
import com.r_z.entity.Repertory;
//import com.r_z.feign.PurchaseFeign;
import com.r_z.result.CommonResult;
import com.r_z.service.RepertoryService;
import com.r_z.util.RequestMsg;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 任俊杰
 * @version 1.0
 * @date 2023/5/30
 */
@RestController
@CrossOrigin
public class RepertoryController {
    //导入service接口
    @Resource
    private RepertoryService repertoryService;
    //导入采购feign接口
    //@Resource
    //PurchaseFeign purchaseFeign;

    /**
     * 查询全部库存信息
     * @param page 当前页
     * @param limit 每页显示数
     * @param productName 库存名称
     * @return map 集合
     */
    @GetMapping("/selectRepertory")
    public CommonResult<Repertory> selectRepertory(Integer page,Integer limit,String productName){
        System.out.println("进来了查询全部库存的方法");
        //查询全部库存（商品）信息，且通过商品名称进行模糊查询
        List<Repertory> repertoryList = repertoryService.selectRepertory(page, limit, productName);
        int count = repertoryService.getTotal(productName);
        return RequestMsg.msg(count,repertoryList);

    }


    /**
     * 库存 增加
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @PostMapping("/addRepertory")
    public int addRepertory(Repertory repertory){
        //System.out.println("增加："+repertory);
        //调用增加库存的方法
        return repertoryService.addRepertory(repertory);
    }

    /**
     * 库存 修改
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @PutMapping("/updateRepertory")
    public int updateRepertory(Repertory repertory){
        //System.out.println("修改："+repertory);
        //调用库存修改的方法
        return repertoryService.updateRepertory(repertory);
    }

    /**
     * 库存 删除
     * @param repertory 库存对象
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @DeleteMapping("/delete")
    public int delete(Repertory repertory){
        //调用库存删除的方法
        return repertoryService.deleteRepertory(repertory);
    }

    /**
     * 采购计划
     * @return
     */
//    public boolean insertPurchasePlan(){
//        return purchaseFeign.insertPurchasePlan();
//    }

}
